package autoschedule.ui;

/*
 NAME:  Juan C. Garcia ID# 56469701
 CERTIFICATION: I certify that this work is my own and that
 none of it is the work of any other person.
 */
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import alarm.*;
import autoteam.Local;
import autoteam.ui.AutoTeamFrame;
import controller.*;

/**
 * GCalendar is a bean for entering a date by choosing the year, month and day.
 * 
 * @author Kai Toedter
 * @version $LastChangedRevision: 95 $
 * @version $LastChangedDate: 2006-05-05 18:43:15 +0200 (Fr, 05 Mai 2006) $
 */
public class GCalendar extends JPanel implements PropertyChangeListener {
	private static final long serialVersionUID = 8913369762644440133L;

	private Calendar calendar;

	/** the day chooser */
	protected DaySelector dayChooser;
	private boolean initialized = false;

	/** indicates if weeks of year shall be visible */
	protected boolean weekOfYearVisible = true;

	/** the locale */
	protected Locale locale;

	/** the month chooser */
	protected MonthChooser monthChooser;

	private JPanel monthYearPanel;

	private JPanel noticePanel;

	/** the year chhoser */
	protected YearChooser yearChooser;

	protected Date minSelectableDate;

	protected Date maxSelectableDate;

	private boolean GameOn;
	
	private AlarmSystem alarm;
	
	private RSMSController control;

	/**
	 * Default GCalendar constructor.
	 */
	public GCalendar() {
		this(null, null, true, true);
		control = new RSMSController();
		alarm = new AlarmSystem(control.getCurUser().getUsername()+"_"+control.getCurSport());
	}

	/**
	 * GCalendar constructor which allows the initial date to be set.
	 * 
	 * @param date
	 *            the date
	 */
	public GCalendar(Date date) {
		this(date, null, true, true);
	}

	/**
	 * GCalendar constructor which allows the initial calendar to be set.
	 * 
	 * @param calendar
	 *            the calendar
	 */
	public GCalendar(Calendar calendar) {
		this(null, null, true, true);
		setCalendar(calendar);
	}

	/**
	 * GCalendar constructor allowing the initial locale to be set.
	 * 
	 * @param locale
	 *            the new locale
	 */
	public GCalendar(Locale locale) {
		this(null, locale, true, true);
	}

	/**
	 * GCalendar constructor specifying both the initial date and locale.
	 * 
	 * @param date
	 *            the date
	 * @param locale
	 *            the new locale
	 */
	public GCalendar(Date date, Locale locale) {
		this(date, locale, true, true);
	}

	/**
	 * GCalendar constructor specifying both the initial date and the month
	 * spinner type.
	 * 
	 * @param date
	 *            the date
	 * @param monthSpinner
	 *            false, if no month spinner should be used
	 */
	public GCalendar(Date date, boolean monthSpinner) {
		this(date, null, monthSpinner, true);
	}

	/**
	 * GCalendar constructor specifying both the locale and the month spinner.
	 * 
	 * @param locale
	 *            the locale
	 * @param monthSpinner
	 *            false, if no month spinner should be used
	 */
	public GCalendar(Locale locale, boolean monthSpinner) {
		this(null, locale, monthSpinner, true);
	}

	/**
	 * GCalendar constructor specifying the month spinner type.
	 * 
	 * @param monthSpinner
	 *            false, if no month spinner should be used
	 */
	public GCalendar(boolean monthSpinner) {
		this(null, null, monthSpinner, true);
	}

	/**
	 * GCalendar constructor with month spinner parameter.
	 * 
	 * @param date
	 *            the date
	 * @param locale
	 *            the locale
	 * @param monthSpinner
	 *            false, if no month spinner should be used
	 * @param weekOfYearVisible
	 *            true, if weeks of year shall be visible
	 */
	public GCalendar(Date date, Locale locale, boolean monthSpinner,
			boolean weekOfYearVisible) {

		setName("JCalendar");

		// needed for setFont() etc.
		dayChooser = null;
		monthChooser = null;
		yearChooser = null;
		this.weekOfYearVisible = weekOfYearVisible;

		this.locale = locale;

		if (locale == null) {
			this.locale = Locale.getDefault();
		}

		calendar = Calendar.getInstance();

		setLayout(new BorderLayout());

		monthYearPanel = new JPanel();
		monthYearPanel.setLayout(new BorderLayout());

		monthChooser = new MonthChooser(monthSpinner);
		yearChooser = new YearChooser();
		monthChooser.setYearChooser(yearChooser);
		monthYearPanel.add(monthChooser, BorderLayout.WEST);
		monthYearPanel.add(yearChooser, BorderLayout.CENTER);
		monthYearPanel.setBorder(BorderFactory.createEmptyBorder());

		JButton Add_Notice = new JButton("Add Notice");
		JButton ClearAll_Notice = new JButton("Clear Calendar");
		noticePanel = new JPanel();
		noticePanel.add(Add_Notice, BorderLayout.CENTER);
		noticePanel.add(ClearAll_Notice,BorderLayout.CENTER);
		
		noticePanel.setBorder(BorderFactory.createEmptyBorder());

		Add_Notice.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addNoticeFrame();
			}
		});
		
		ClearAll_Notice.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				clearCalendar();
			}
		});

		dayChooser = new DaySelector(weekOfYearVisible);
		dayChooser.addPropertyChangeListener(this);
		monthChooser.setDayChooser(dayChooser);
		monthChooser.addPropertyChangeListener(this);
		yearChooser.setDayChooser(dayChooser);
		yearChooser.addPropertyChangeListener(this);
		add(noticePanel, BorderLayout.SOUTH);
		add(monthYearPanel, BorderLayout.NORTH);
		add(dayChooser, BorderLayout.CENTER);

		// Set the initialized flag before setting the calendar. This will
		// cause the other components to be updated properly.
		if (date != null) {
			calendar.setTime(date);
		}

		initialized = true;

		setCalendar(calendar);

	}
	private void clearCalendar()
	{
		alarm.connectToDB();
		alarm.removeAllNotices();
		alarm.disconnectFromDB();
		this.refreshCalendar();
	}
	
	private void addNoticeFrame() {
		final JFrame addNotice = new JFrame("Add Notice");
		JPanel inside = new JPanel();

		addNotice.setResizable(false);
		addNotice.setSize(240, 240);

		// The Program starts with notice as the default reminder
		GameOn = false;
		JButton submit = new JButton("Submit");
		submit.setFocusPainted(false);
		final JButton message = new JButton("Notice");
		final JButton game = new JButton("Game");
		final JLabel noticeName = new JLabel("Enter notice: ");
		JLabel noticeDay = new JLabel("Enter Day: ");
		JLabel noticeStart = new JLabel("Enter Start Time: ");
		JLabel noticeEnd = new JLabel("Enter End Time: ");
		JLabel noticeType = new JLabel("Type");

		final JTextArea NameArea = createJText(6, 1);
		final JTextArea DayArea = createJText(6, 1);
		DayArea.setText("ddmmyyyy");
		final JTextArea StartArea = createJText(6, 1);
		StartArea.setText("hh:mm AM or PM");
		final JTextArea EndArea = createJText(6, 1);
		EndArea.setText("hh:mm AM or PM");

		message.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				GameOn = false;
				message.setEnabled(false);
				game.setEnabled(true);
				noticeName.setText("Enter notice: ");
			}
		});

		game.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				GameOn = true;
				game.setEnabled(false);
				message.setEnabled(true);
				noticeName.setText("Enter game: ");
			}
		});

		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String day = DayArea.getText();
				String start = StartArea.getText();
				String end = EndArea.getText();
				int M, D, Y;
				int StartHour, StartMin, EndHour, EndMin;
				try {
					
					D = Integer.parseInt(day.substring(0, 2));
					M = Integer.parseInt(day.substring(2, 4)) - 1;
					Y = Integer.parseInt(day.substring(4)) - 1900;
					Date Start = new Date(Y, M, D);
					int index = start.indexOf(":");
					if( ! start.substring(index+4).equalsIgnoreCase("am"))
					{
						// When is 12 pm the start hour is still 12
						if(Integer.parseInt(start.substring(0,index)) == 12)
						{
							StartHour = 12;
						}
						else
						{
						StartHour = Integer.parseInt(start.substring(0,index))+12;
						}
						StartMin = Integer.parseInt(start.substring(index+1,index+3));
					}
					else
					{
						
						StartHour = Integer.parseInt(start.substring(0,index));
						StartMin = Integer.parseInt(start.substring(index+1,index+3));
					}
					//System.out.println("The START time is : " + StartHour + "," + StartMin);
					
					Start.setHours(StartHour);
					Start.setMinutes(StartMin);
					
					index = end.indexOf(":");
					Date End = new Date(Y, M, D);
					if( ! end.substring(index+4).equalsIgnoreCase("am"))
					{
						EndHour = Integer.parseInt(end.substring(0,index))+12;
						EndMin = Integer.parseInt(end.substring(index+1,index+3));
					}
					else
					{
						EndHour = Integer.parseInt(end.substring(0,index));
						EndMin = Integer.parseInt(end.substring(index+1,index+3));
					}
					
					//System.out.println("The END time is : " + EndHour + "," + EndMin);
//					
					End.setHours(EndHour);
					
					End.setMinutes(EndMin);

//					System.out.println("The name is : " + NameArea.getText());
//					System.out.println("The Day is : " + DayArea.getText());
//					System.out.println("The Start is : " + StartArea.getText());
//					System.out.println("The End is : " + EndArea.getText());

					Calendar check = Calendar.getInstance();
					Date checkDate = check.getTime();
					if (NameArea.getText().equals("")
							|| DayArea.getText().equals("")
							|| StartArea.getText().equals("")
							|| EndArea.getText().equals("")) 
					{
						JOptionPane.showMessageDialog(null,
								"Fill out all the fields before submitting",
								Local.get("Error"), JOptionPane.ERROR_MESSAGE,
								null);
					}
					else if (checkDate.after(Start))
					{
						
						JOptionPane.showMessageDialog(null,
								"Notices can't be set to a past date",
								Local.get("Error"), JOptionPane.ERROR_MESSAGE,
								null);
					}
					else if ((checkDate.compareTo(Start) == 0 ) && (checkDate.getHours() > Start.getHours()))
					{
							JOptionPane.showMessageDialog(null,
									"Notices can't start in a past hour",
									Local.get("Error"), JOptionPane.ERROR_MESSAGE,
									null);
					}
					else {
						Notice notice0;
						//System.out.print("Then Start hour is : "+ Start.getHours());
						//System.out.print("Then End hour is : "+ End.getHours());
						if (GameOn) {
							notice0 = new Notice(Start, End, NameArea
									.getText(), "game");

						} else {
							notice0 = new Notice(Start, End, NameArea
									.getText(), "notice");
						}
						//alarm.connectToDB();
						//System.out.println("Information about User:");
						//System.out.println(control.getCurUser().getUsername()+"_"+control.getCurSport());
						alarm.addNotice(notice0);
						//alarm.disconnectFromDB();
						dayChooser.init();
						addNotice.setVisible(false);
					}

				} catch (NumberFormatException ee) {
					JOptionPane.showMessageDialog(null,
							"Fill out the correct day", Local.get("Error"),
							JOptionPane.ERROR_MESSAGE, null);

				}

			}
		});
		inside.setLayout(new GridBagLayout());
		GridBagConstraints constrain = new GridBagConstraints();

		constrain.weightx = 1;
		constrain.weighty = 1;
		constrain.gridx = 0;
		constrain.gridy = 0;
		inside.add(noticeName, constrain);

		constrain.gridx = 1;
		constrain.gridy = 0;
		inside.add(NameArea, constrain);

		constrain.gridx = 0;
		constrain.gridy = 1;
		inside.add(noticeDay, constrain);

		constrain.gridx = 1;
		constrain.gridy = 1;
		inside.add(DayArea, constrain);

		constrain.gridx = 0;
		constrain.gridy = 2;
		inside.add(noticeStart, constrain);

		constrain.gridx = 1;
		constrain.gridy = 2;
		inside.add(StartArea, constrain);

		constrain.gridx = 0;
		constrain.gridy = 3;
		inside.add(noticeEnd, constrain);

		constrain.gridx = 1;
		constrain.gridy = 3;
		inside.add(EndArea, constrain);

		constrain.gridx = 0;
		constrain.gridy = 4;
		inside.add(game, constrain);

		constrain.gridx = 1;
		constrain.gridy = 4;
		inside.add(message, constrain);

		message.setEnabled(false);

		constrain.gridx = 1;
		constrain.gridy = 5;
		inside.add(submit, constrain);

		// Set up the localization
		String language;
		String country;
		language = new String("en");
		country = new String("US");
		Local.initialize(language, country);

		addNotice.add(inside);
		addNotice.setVisible(true);
	}

	private JTextArea createJText(int x, int y) {
		JTextArea jtext = new JTextArea(x, y);
		jtext.setText("");
		jtext.setBorder(BorderFactory.createLineBorder(Color.black));
		jtext.setEditable(true);
		jtext.setLineWrap(true);
		jtext.setWrapStyleWord(true);

		return jtext;
	}

	/**
	 * Creates a JFrame with a GCalendar inside and can be used for testing.
	 * 
	 * @param s
	 *            The command line arguments
	 */
	public static void main(String[] s) {
		JFrame frame = new JFrame("JCalendar");

		GCalendar jcalendar = new GCalendar();
		frame.getContentPane().add(jcalendar);
		frame.pack();
		frame.setVisible(true);
	}

	/**
	 * Returns the calendar property.
	 * 
	 * @return the value of the calendar property.
	 */
	public Calendar getCalendar() {
		return calendar;
	}

	/**
	 * Gets the dayChooser attribute of the GCalendar object
	 * 
	 * @return the dayChooser value
	 */
	public DaySelector getDayChooser() {
		return dayChooser;
	}

	/**
	 * Returns the locale.
	 * 
	 * @return the value of the locale property.
	 * 
	 * @see #setLocale
	 */
	public Locale getLocale() {
		return locale;
	}

	/**
	 * Gets the monthChooser attribute of the GCalendar object
	 * 
	 * @return the monthChooser value
	 */
	public MonthChooser getMonthChooser() {
		return monthChooser;
	}

	/**
	 * Gets the yearChooser attribute of the GCalendar object
	 * 
	 * @return the yearChooser value
	 */
	public YearChooser getYearChooser() {
		return yearChooser;
	}

	/**
	 * Indicates if the weeks of year are visible..
	 * 
	 * @return boolean true, if weeks of year are visible
	 */
	public boolean isWeekOfYearVisible() {
		return dayChooser.isWeekOfYearVisible();
	}

	/**
	 * GCalendar is a PropertyChangeListener, for its day, month and year
	 * chooser.
	 * 
	 * @param evt
	 *            the property change event
	 */
	public void propertyChange(PropertyChangeEvent evt) {
		if (calendar != null) {
			Calendar c = (Calendar) calendar.clone();

			if (evt.getPropertyName().equals("day")) {
				c.set(Calendar.DAY_OF_MONTH, ((Integer) evt.getNewValue())
						.intValue());
				setCalendar(c, false);
			} else if (evt.getPropertyName().equals("month")) {
				c.set(Calendar.MONTH, ((Integer) evt.getNewValue()).intValue());
				setCalendar(c, false);
			} else if (evt.getPropertyName().equals("year")) {
				c.set(Calendar.YEAR, ((Integer) evt.getNewValue()).intValue());
				setCalendar(c, false);
			} else if (evt.getPropertyName().equals("date")) {
				c.setTime((Date) evt.getNewValue());
				setCalendar(c, true);
			}
		}
	}

	/**
	 * Sets the background color.
	 * 
	 * @param bg
	 *            the new background
	 */
	public void setBackground(Color bg) {
		super.setBackground(bg);

		if (dayChooser != null) {
			dayChooser.setBackground(bg);
		}
	}

	/**
	 * Sets the calendar property. This is a bound property.
	 * 
	 * @param c
	 *            the new calendar
	 * @throws NullPointerException
	 *             - if c is null;
	 * @see #getCalendar
	 */
	public void setCalendar(Calendar c) {
		setCalendar(c, true);
	}

	/**
	 * Sets the calendar attribute of the GCalendar object
	 * 
	 * @param c
	 *            the new calendar value
	 * @param update
	 *            the new calendar value
	 * @throws NullPointerException
	 *             - if c is null;
	 */
	private void setCalendar(Calendar c, boolean update) {
		if (c == null) {
			setDate(null);
		}
		Calendar oldCalendar = calendar;
		calendar = c;

		if (update) {
			yearChooser.setYear(c.get(Calendar.YEAR));
			monthChooser.setMonth(c.get(Calendar.MONTH));
			dayChooser.setDay(c.get(Calendar.DATE));
		}

		firePropertyChange("calendar", oldCalendar, calendar);
	}

	/**
	 * Enable or disable the GCalendar.
	 * 
	 * @param enabled
	 *            the new enabled value
	 */
	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);

		if (dayChooser != null) {
			dayChooser.setEnabled(enabled);
			monthChooser.setEnabled(enabled);
			yearChooser.setEnabled(enabled);
		}
	}

	/**
	 * Returns true, if enabled.
	 * 
	 * @return true, if enabled.
	 */
	public boolean isEnabled() {
		return super.isEnabled();
	}

	/**
	 * Sets the font property.
	 * 
	 * @param font
	 *            the new font
	 */
	public void setFont(Font font) {
		super.setFont(font);

		if (dayChooser != null) {
			dayChooser.setFont(font);
			monthChooser.setFont(font);
			yearChooser.setFont(font);
		}
	}

	/**
	 * Sets the foreground color.
	 * 
	 * @param fg
	 *            the new foreground
	 */
	public void setForeground(Color fg) {
		super.setForeground(fg);

		if (dayChooser != null) {
			dayChooser.setForeground(fg);
			monthChooser.setForeground(fg);
			yearChooser.setForeground(fg);
		}
	}

	/**
	 * Sets the locale property. This is a bound property.
	 * 
	 * @param l
	 *            the new locale value
	 * 
	 * @see #getLocale
	 */
	public void setLocale(Locale l) {
		if (!initialized) {
			super.setLocale(l);
		} else {
			Locale oldLocale = locale;
			locale = l;
			dayChooser.setLocale(locale);
			monthChooser.setLocale(locale);
			firePropertyChange("locale", oldLocale, locale);
		}
	}

	/**
	 * Sets the week of year visible.
	 * 
	 * @param weekOfYearVisible
	 *            true, if weeks of year shall be visible
	 */
	public void setWeekOfYearVisible(boolean weekOfYearVisible) {
		dayChooser.setWeekOfYearVisible(weekOfYearVisible);
		setLocale(locale); // hack for doing complete new layout :)
	}

	/**
	 * Gets the visibility of the decoration background.
	 * 
	 * @return true, if the decoration background is visible.
	 */
	public boolean isDecorationBackgroundVisible() {
		return dayChooser.isDecorationBackgroundVisible();
	}

	/**
	 * Sets the decoration background visible.
	 * 
	 * @param decorationBackgroundVisible
	 *            true, if the decoration background should be visible.
	 */
	public void setDecorationBackgroundVisible(
			boolean decorationBackgroundVisible) {
		dayChooser.setDecorationBackgroundVisible(decorationBackgroundVisible);
		setLocale(locale); // hack for doing complete new layout :)
	}

	/**
	 * Gets the visibility of the decoration border.
	 * 
	 * @return true, if the decoration border is visible.
	 */
	public boolean isDecorationBordersVisible() {
		return dayChooser.isDecorationBordersVisible();
	}

	/**
	 * Sets the decoration borders visible.
	 * 
	 * @param decorationBordersVisible
	 *            true, if the decoration borders should be visible.
	 */
	public void setDecorationBordersVisible(boolean decorationBordersVisible) {
		dayChooser.setDecorationBordersVisible(decorationBordersVisible);
		setLocale(locale); // hack for doing complete new layout :)
	}

	/**
	 * Returns the color of the decoration (day names and weeks).
	 * 
	 * @return the color of the decoration (day names and weeks).
	 */
	public Color getDecorationBackgroundColor() {
		return dayChooser.getDecorationBackgroundColor();
	}

	/**
	 * Sets the background of days and weeks of year buttons.
	 * 
	 * @param decorationBackgroundColor
	 *            the background color
	 */
	public void setDecorationBackgroundColor(Color decorationBackgroundColor) {
		dayChooser.setDecorationBackgroundColor(decorationBackgroundColor);
	}

	/**
	 * Returns the Sunday foreground.
	 * 
	 * @return Color the Sunday foreground.
	 */
	public Color getSundayForeground() {
		return dayChooser.getSundayForeground();
	}

	/**
	 * Returns the weekday foreground.
	 * 
	 * @return Color the weekday foreground.
	 */
	public Color getWeekdayForeground() {
		return dayChooser.getWeekdayForeground();
	}

	/**
	 * Sets the Sunday foreground.
	 * 
	 * @param sundayForeground
	 *            the sundayForeground to set
	 */
	public void setSundayForeground(Color sundayForeground) {
		dayChooser.setSundayForeground(sundayForeground);
	}

	/**
	 * Sets the weekday foreground.
	 * 
	 * @param weekdayForeground
	 *            the weekdayForeground to set
	 */
	public void setWeekdayForeground(Color weekdayForeground) {
		dayChooser.setWeekdayForeground(weekdayForeground);
	}

	/**
	 * Returns a Date object.
	 * 
	 * @return a date object constructed from the calendar property.
	 */
	public Date getDate() {
		return new Date(calendar.getTimeInMillis());
	}

	/**
	 * Sets the date. Fires the property change "date".
	 * 
	 * @param date
	 *            the new date.
	 * @throws NullPointerException
	 *             - if tha date is null
	 */
	public void setDate(Date date) {
		Date oldDate = calendar.getTime();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DAY_OF_MONTH);

		yearChooser.setYear(year);
		monthChooser.setMonth(month);
		dayChooser.setCalendar(calendar);
		dayChooser.setDay(day);

		firePropertyChange("date", oldDate, date);
	}

	/**
	 * Sets a valid date range for selectable dates. If max is before min, the
	 * default range with no limitation is set.
	 * 
	 * @param min
	 *            the minimum selectable date or null (then the minimum date is
	 *            set to 01\01\0001)
	 * @param max
	 *            the maximum selectable date or null (then the maximum date is
	 *            set to 01\01\9999)
	 */
	public void setSelectableDateRange(Date min, Date max) {
		dayChooser.setSelectableDateRange(min, max);
	};

	/**
	 * Gets the minimum selectable date.
	 * 
	 * @return the minimum selectable date
	 */
	public Date getMaxSelectableDate() {
		return dayChooser.getMaxSelectableDate();
	}

	/**
	 * Gets the maximum selectable date.
	 * 
	 * @return the maximum selectable date
	 */
	public Date getMinSelectableDate() {
		return dayChooser.getMinSelectableDate();
	}

	/**
	 * Sets the maximum selectable date.
	 * 
	 * @param max
	 *            maximum selectable date
	 */
	public void setMaxSelectableDate(Date max) {
		dayChooser.setMaxSelectableDate(max);
	}

	/**
	 * Sets the minimum selectable date.
	 * 
	 * @param min
	 *            minimum selectable date
	 */
	public void setMinSelectableDate(Date min) {
		dayChooser.setMinSelectableDate(min);
	}

	/**
	 * Gets the maximum number of characters of a day name or 0. If 0 is
	 * returned, dateFormatSymbols.getShortWeekdays() will be used.
	 * 
	 * @return the maximum number of characters of a day name or 0.
	 */
	public int getMaxDayCharacters() {
		return dayChooser.getMaxDayCharacters();
	}

	/**
	 * Sets the maximum number of characters per day in the day bar. Valid
	 * values are 0-4. If set to 0, dateFormatSymbols.getShortWeekdays() will be
	 * used, otherwise theses strings will be reduced to the maximum number of
	 * characters.
	 * 
	 * @param maxDayCharacters
	 *            the maximum number of characters of a day name.
	 */
	public void setMaxDayCharacters(int maxDayCharacters) {
		dayChooser.setMaxDayCharacters(maxDayCharacters);
	}
	
	/*
	 * Refresher
	 */
	 public void refreshCalendar()
	 {
		 dayChooser.init();
	 }
	 
	
	
}
